package cn.neusoft.controller;

import cn.neusoft.pojo.Dept;
import cn.neusoft.service.impl.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/dept")
@Api(value = "部门的API",description="部门相关的CRUD功能")
public class DeptController {

    @Autowired
    DeptService deptService;

    /**
     * restful风格
     * @param dept
     * @return
     */
    @ApiOperation(value = "添加部门信息" )
    @PostMapping   // post +  /dept
    public String add(@RequestBody Dept dept){
        return deptService.add(dept);
    }

    @ApiOperation(value = "修改部门信息" )
    @PutMapping   // put +  /dept
    public String update(@RequestBody Dept dept){
        return deptService.update(dept);
    }

    @ApiOperation(value = "删除部门信息" )
    @DeleteMapping("/{deptno}")   // delete + /dept/1115
    public String del(@PathVariable("deptno") Integer deptno){
        return deptService.del(deptno);
    }

    @ApiOperation(value = "根据部门编号查询" )
    @GetMapping("/{deptno}")      //  get + /dept/1115
    public Dept getById(@PathVariable("deptno") Integer deptno){
        return deptService.getById(deptno);
    }

    @ApiOperation(value = "查询所有部门信息" )
    @GetMapping("/all")    //   get  +  /dept/all
    public List<Dept> getAll(){
        return deptService.getAll();
    }

    
}
